﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            alarmHiddenField.Value = string.Empty;
    }
    private void CheckAlarm()
    {
        if (EnergyTypeDropDownList.Items.Count < 2)
            return;
        DateTime startDate = DateTime.Today;
        NoBillCenterSqlDataSource.SelectParameters.Clear();
        NoBillCenterSqlDataSource.SelectCommand = "spCentersBill";
        NoBillCenterSqlDataSource.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
        NoBillCenterSqlDataSource.SelectParameters.Add("StartDate", DateTime.Now.AddDays(-30).ToString());
        NoBillCenterSqlDataSource.SelectParameters.Add("EndDate", DateTime.Now.ToString());
        NoBillCenterSqlDataSource.SelectParameters.Add("Type", "0");

        for (int i = 1; i < EnergyTypeDropDownList.Items.Count; i++)
        {
            EnergyTypeDropDownList.SelectedIndex = i;
            NoBillCenterSqlDataSource.SelectParameters["Type"].DefaultValue = EnergyTypeDropDownList.SelectedValue;
            NoBillCenterSqlDataSource.Select(DataSourceSelectArguments.Empty);
        }
    }
    protected void NoBillCenterSqlDataSource_Selected(object sender, SqlDataSourceStatusEventArgs e)
    {
        if (e.AffectedRows > 0)
            alarmHiddenField.Value += string.Format("تعداد {0} مرکز قبض {1} را در سی روز گذشته ثبت نکرده اند.", e.AffectedRows, EnergyTypeDropDownList.SelectedItem.Text);
    }
    protected void Page_OnPreRenderComplete(object sender, EventArgs e)
    {
        CheckAlarm();
        if (alarmHiddenField.Value != string.Empty)
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "Alarm", string.Format(@"alert(""{0}"");", alarmHiddenField.Value), true);
        EnergyTypeDropDownList.Visible = false;
    }
}